package com.zhima.controller.plain;

import com.zhima.dto.ZhimaOjResult;
import com.zhima.entity.OjQuestionBindBank;
import com.zhima.service.OjQuestionBindBankService;
import com.zhima.util.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zhima.dto.ZhimaOjResult.success;

/**
 * @author : 芝麻
 * @date : 2023-08-27 20:55
 **/
@RestController
@RequestMapping("/question-bind-bank")
public class OjQuestionBindBankController {
    @Autowired
    private OjQuestionBindBankService ojQuestionBindBankService;

    /**
     * 把题目与题单绑定
     *
     * @param questionBindBank
     * @return
     */
    @PostMapping("/bind")
    public ZhimaOjResult bindQuestionToBank(@RequestBody OjQuestionBindBank questionBindBank) {
        return success(ojQuestionBindBankService.bindQuestionToBank(UserHolder.get().getId(), questionBindBank));
    }

    /**
     * 将绑定关系删除
     *
     * @param questionBankId
     * @param questionIndex
     * @return
     */
    @PostMapping("/unbind/{questionBankId}/{questionIndex}")
    public ZhimaOjResult unbindQuestionToBank(@PathVariable("questionBankId") Long questionBankId, @PathVariable("questionIndex") Integer questionIndex) {
        return success(ojQuestionBindBankService.unbindQuestionToBank(UserHolder.get().getId(), questionBankId, questionIndex));
    }

    /**
     * 按照题号顺序修改索引
     *
     * @param afterSequence
     * @param questionBankId
     * @return
     */
    @PostMapping("/change/{questionBankId}")
    public ZhimaOjResult changeQuestionIndex(@RequestBody String[] afterSequence, @PathVariable("questionBankId") Long questionBankId) {
        return success(ojQuestionBindBankService.changeQuestionIndex(questionBankId, afterSequence));
    }
}
